{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [],
   "source": [
    "from selenium import webdriver\n",
    "from selenium.webdriver.support.ui import WebDriverWait\n",
    "from selenium.webdriver.support import expected_conditions as EC\n",
    "from selenium.webdriver.common.by import By"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "options = webdriver.ChromeOptions()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "options.add_argument('lang=zh_CN.UTF-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "options.add_extension(r\"D:\\Python\\IPython\\information\\DogAuthExtension.crx\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver = webdriver.Chrome(chrome_options=options)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.get(r'http://qbt.ecdataway.com/site/login')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# driver.find_element_by_css_selector('#LoginForm_username').send = '森马上海服饰'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_id('LoginForm_username').send_keys('森马上海服饰')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.find_element_by_id('LoginForm_password').send_keys('a123')\n",
    "driver.find_element_by_class_name('login_btn').click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [],
   "source": [
    "driver.get(r'http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50011740')\n",
    "# driver.get(r'http://qbt.ecdataway.com/stat?rcid=2011010114&cid=30')\n",
    "# driver.get(r'http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50011404')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [],
   "source": [
    "# driver.find_element_by_css_selector('#sidebar_category > ul > li:nth-child(1) > a').click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [],
   "source": [
    "# driver.find_element_by_css_selector('#sidebar_category > ul > li:nth-child(1) > a').click()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [],
   "source": [
    "dic_fisrt_floor = {}\n",
    "for link in driver.find_elements_by_xpath(\"//*[@href]\"):\n",
    "    href = link.get_attribute('href')\n",
    "    if 'rcid' in href and '#' not in href:\n",
    "        dic_fisrt_floor[link.text] = href"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'服饰鞋包': 'http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114',\n",
       " '靴子': 'http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50011743',\n",
       " '帆布鞋': 'http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50011744',\n",
       " '凉鞋': 'http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50011745',\n",
       " '拖鞋': 'http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50011746',\n",
       " '低帮鞋': 'http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012906',\n",
       " '高帮鞋': 'http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012907',\n",
       " '雨鞋': 'http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012908'}"
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# dic_fisrt_floor.pop('服饰鞋包')\n",
    "# dic_fisrt_floor.pop('')\n",
    "dic_fisrt_floor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {},
   "outputs": [],
   "source": [
    "json_first_floor = json.dumps(dic_fisrt_floor, ensure_ascii=False)\n",
    "with open('I:\\\\男鞋分类.json', 'a', encoding='utf-8') as f:\n",
    "    f.write(json_first_floor)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "metadata": {},
   "outputs": [],
   "source": [
    "locator = (By.ID, 'header')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " 短袜/打底袜/丝袜/美腿袜 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50006846\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 文胸 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50008881\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 内裤 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50008882\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 文胸套装 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50008883\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 塑身上衣 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50008884\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 保暖上装 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50008885\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 睡衣上装 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50008886\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 抹胸 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50008888\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 乳贴 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50008889\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 肚兜 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50008890\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 吊带/背心/T恤 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50010394\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 睡裤/家居裤 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012766\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 睡裙 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012771\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 睡衣/家居服套装 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012772\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 睡袍/浴袍 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012773\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 塑身美体裤 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012774\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 塑身腰封/腰夹 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012775\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 塑身分体套装 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012776\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 保暖裤 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012777\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 保暖套装 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012778\n",
      "服饰鞋包 http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114\n",
      "\n",
      " 塑身连体衣 http://qbt.ecdataway.com/stat?rcid=2011010114&cid=50012781\n",
      "time is short\n"
     ]
    },
    {
     "ename": "StaleElementReferenceException",
     "evalue": "Message: stale element reference: element is not attached to the page document\n  (Session info: chrome=68.0.3440.84)\n  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.2.9200 x86_64)\n",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mStaleElementReferenceException\u001b[0m            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-155-8fb014316a6f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m     13\u001b[0m     \u001b[0mlst\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     14\u001b[0m     \u001b[1;32mfor\u001b[0m \u001b[0mlink\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mall_href\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 15\u001b[1;33m         \u001b[0mhref\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlink\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_attribute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'href'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     16\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[1;34m'rcid'\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mhref\u001b[0m \u001b[1;32mand\u001b[0m \u001b[1;34m'#'\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mhref\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     17\u001b[0m             \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlink\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtext\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mhref\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Anaconda\\lib\\site-packages\\selenium-3.14.0-py3.6.egg\\selenium\\webdriver\\remote\\webelement.py\u001b[0m in \u001b[0;36mget_attribute\u001b[1;34m(self, name)\u001b[0m\n\u001b[0;32m    141\u001b[0m                 self, name)\n\u001b[0;32m    142\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 143\u001b[1;33m             \u001b[0mresp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_execute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mCommand\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mGET_ELEMENT_ATTRIBUTE\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;34m'name'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    144\u001b[0m             \u001b[0mattributeValue\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'value'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    145\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mattributeValue\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Anaconda\\lib\\site-packages\\selenium-3.14.0-py3.6.egg\\selenium\\webdriver\\remote\\webelement.py\u001b[0m in \u001b[0;36m_execute\u001b[1;34m(self, command, params)\u001b[0m\n\u001b[0;32m    626\u001b[0m             \u001b[0mparams\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    627\u001b[0m         \u001b[0mparams\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'id'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_id\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 628\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_parent\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcommand\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    629\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    630\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mfind_element\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mby\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mBy\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mID\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Anaconda\\lib\\site-packages\\selenium-3.14.0-py3.6.egg\\selenium\\webdriver\\remote\\webdriver.py\u001b[0m in \u001b[0;36mexecute\u001b[1;34m(self, driver_command, params)\u001b[0m\n\u001b[0;32m    318\u001b[0m         \u001b[0mresponse\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommand_executor\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdriver_command\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    319\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mresponse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 320\u001b[1;33m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merror_handler\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcheck_response\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresponse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    321\u001b[0m             response['value'] = self._unwrap_value(\n\u001b[0;32m    322\u001b[0m                 response.get('value', None))\n",
      "\u001b[1;32mD:\\Anaconda\\lib\\site-packages\\selenium-3.14.0-py3.6.egg\\selenium\\webdriver\\remote\\errorhandler.py\u001b[0m in \u001b[0;36mcheck_response\u001b[1;34m(self, response)\u001b[0m\n\u001b[0;32m    240\u001b[0m                 \u001b[0malert_text\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'alert'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'text'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    241\u001b[0m             \u001b[1;32mraise\u001b[0m \u001b[0mexception_class\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscreen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstacktrace\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0malert_text\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 242\u001b[1;33m         \u001b[1;32mraise\u001b[0m \u001b[0mexception_class\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mscreen\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstacktrace\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    243\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    244\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m_value_or_default\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdefault\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mStaleElementReferenceException\u001b[0m: Message: stale element reference: element is not attached to the page document\n  (Session info: chrome=68.0.3440.84)\n  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 6.2.9200 x86_64)\n"
     ]
    }
   ],
   "source": [
    "dic_second_floor = {}\n",
    "dic_relation = {}\n",
    "for name in dic_fisrt_floor:\n",
    "    url = dic_fisrt_floor[name]\n",
    "    print('\\n', name, url)\n",
    "    driver.get(url)\n",
    "    try:\n",
    "        ele = WebDriverWait(driver, 30).until(EC.presence_of_element_located(locator))\n",
    "        driver.implicitly_wait(5)\n",
    "        all_href = driver.find_elements_by_xpath(\"//*[@href]\")\n",
    "    except:\n",
    "        print('time is short')\n",
    "    lst = []\n",
    "    for link in all_href:\n",
    "        href = link.get_attribute('href')\n",
    "        if 'rcid' in href and '#' not in href:\n",
    "            print(link.text, href)\n",
    "            lst.append(link.text)\n",
    "            dic_second_floor[link.text] = href\n",
    "            dic_relation[name] = lst"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'短袜/打底袜/丝袜/美腿袜': ['服饰鞋包'],\n",
       " '文胸': ['服饰鞋包'],\n",
       " '内裤': ['服饰鞋包'],\n",
       " '文胸套装': ['服饰鞋包'],\n",
       " '塑身上衣': ['服饰鞋包'],\n",
       " '保暖上装': ['服饰鞋包'],\n",
       " '睡衣上装': ['服饰鞋包'],\n",
       " '抹胸': ['服饰鞋包'],\n",
       " '乳贴': ['服饰鞋包'],\n",
       " '肚兜': ['服饰鞋包'],\n",
       " '吊带/背心/T恤': ['服饰鞋包'],\n",
       " '睡裤/家居裤': ['服饰鞋包'],\n",
       " '睡裙': ['服饰鞋包'],\n",
       " '睡衣/家居服套装': ['服饰鞋包'],\n",
       " '睡袍/浴袍': ['服饰鞋包'],\n",
       " '塑身美体裤': ['服饰鞋包'],\n",
       " '塑身腰封/腰夹': ['服饰鞋包'],\n",
       " '塑身分体套装': ['服饰鞋包'],\n",
       " '保暖裤': ['服饰鞋包'],\n",
       " '保暖套装': ['服饰鞋包']}"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# dic_second_floor\n",
    "dic_relation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [],
   "source": [
    "json_relation = json.dumps(dic_relation, ensure_ascii=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('i:\\\\男装细分品类.json', 'w', encoding='utf-8') as f:\n",
    "    f.write(json_relation)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'服饰鞋包': 'http://qbt.ecdataway.com/stat?cid=0&rcid=2011010114'}"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dic_second_floor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "dic_init_floor = {}\n",
    "for link in driver.find_elements_by_xpath(\"//*[@href]\"):\n",
    "    href = link.get_attribute('href')\n",
    "    if 'rcid' in href and '#' not in href:\n",
    "        dic_init_floor[link.text] = href"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [],
   "source": [
    "json_init_floor = json.dumps(dic_init_floor, ensure_ascii=False)\n",
    "with open('I:\\\\初始分类.json', 'w', encoding='utf-8') as f:\n",
    "    f.write(json_init_floor)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
